package name.fowler.refactoring.simplestore;

import java.util.ArrayList;
import java.util.List;

import name.fowler.refactoring.simplestore.strategy.FilmCategoryStrategy;

public class Customer {
	private String m_Name;
	private List<Rental> m_Rentals = new ArrayList<Rental>();
	
	public Customer(String name) {
		m_Name = name;
		
	}

	public String getName() {
		return m_Name;
	}


	public void addRental(Rental arg){
		m_Rentals.add(arg);
	}

	public String statement()
	{
	
		int frequentRenterPoints = 0;
				
		String result = "Rental record for " + m_Name + "\n";
		
		
		double totalAmount = 0;
		for(Rental each: m_Rentals) {
			double thisAmount = each.getAmount();
			// // Determine amounts for each line
			// switch(each.getMovie().getPriceCode()) {
			// case Regular:
			// thisAmount += 2;
			// if (each.getDaysRented() > 2)
			// {
			// thisAmount += (each.getDaysRented() - 2) * 1.5;
			// }
			// break;
			//
			// case NewRelease:
			// thisAmount += each.getDaysRented() * 3;
			// break;
			//
			// case Childrens:
			// thisAmount += 1.5;
			// if (each.getDaysRented() > 3)
			// {
			// thisAmount = (each.getDaysRented() - 3) * 1.5;
			// }
			// break;
			// }
			frequentRenterPoints =  countFrequency(frequentRenterPoints, each);
			// Show figures for this rental
			result += "\t" + each.getMovie().getTitle() + "\t" + thisAmount + "\n";
		}
		totalAmount = getTotalAmount();
		// Add footer lines
		result += "Amount owed is " + totalAmount + "\n";
		result += "You earned " + frequentRenterPoints + " frequent renter points.";
		return result;
	}

	public double getTotalAmount() {
		double totalAmount = 0;
		for(Rental each: m_Rentals) {
			double thisAmount = each.getAmount();
			totalAmount += thisAmount;
		}
		return totalAmount;
	}

	public int countFrequency(int frequentRenterPoints, Rental each) {
		
		// // Add frequent renter points
		// int freq = frequentRenterPoints++;
		//
		// // Add bonus for a two-day new-release rental
		// if ((each.getDaysRented() > 1))
		// {
		// freq ++;
		// }
		return each.countFrequency();
	}
}

